#ifndef PRINTERCONTROL_H
#define PRINTERCONTROL_H

#include <QDebug>
#include <QMutex>
#include <QObject>
#include <QSerialPort>
#include <QSerialPortInfo>

class PrinterControl : public QObject
{
    Q_OBJECT

    // 打印机类型
    Q_PROPERTY(int PrinterType READ PrinterType WRITE setPrinterType NOTIFY PrinterTypeChanged FINAL)
    // 当前语言类型
    Q_PROPERTY(int CurrentLanguage READ CurrentLanguage WRITE setCurrentLanguage NOTIFY
                   CurrentLanguageChanged FINAL)

    // 材料名称
    Q_PROPERTY(QString MaterialName READ MaterialName WRITE setMaterialName NOTIFY
                   MaterialNameChanged FINAL)
    // 客户名称
    Q_PROPERTY(QString CustomerName READ CustomerName WRITE setCustomerName NOTIFY
                   CustomerNameChanged FINAL)

public slots:

    void recv_Auto_Printer_Message_Slots(bool left,
                                         bool right,
                                         QString materialHeight,
                                         QString materialLength);

public:
    static PrinterControl *getInstance(QObject *parent);
    static PrinterControl *m_instance;
    static QMutex m_mutex;

    // 设置 打印机连接参数
    void setConnectParameter(
        QString serialPort, QString baudRate, QString dataBit, QString parityBit, QString stopBit);
    // 连接打印机
    void connectToDevice();

    // 手动打印动作
    Q_INVOKABLE void printerActive(QString materialHeight,
                                   QString materialLength,
                                   QString leftAngle,
                                   QString rightAngle);

    // 瑞工打印动作 - 中文
    void printer_Active_RuiGong_Zh(QString MaterialHeight,
                                   QString MaterialLength,
                                   QString LeftAngle,
                                   QString RightAngle,
                                   QString MaterialName,
                                   QString Customer);
    // 瑞工打印动作 - 英文
    void printer_Active_RuiGong_En(QString MaterialHeight,
                                   QString MaterialLength,
                                   QString LeftAngle,
                                   QString RightAngle,
                                   QString MaterialName,
                                   QString Customer);
    // 炜煌打印动作 - 中文
    void printer_Active_WeiHuang_Zh(QString MaterialHeight,
                                    QString MaterialLength,
                                    QString LeftAngle,
                                    QString RightAngle,
                                    QString MaterialName,
                                    QString Customer);
    // 炜煌打印动作 - 英文
    void printer_Active_WeiHuang_En(QString MaterialHeight,
                                    QString MaterialLength,
                                    QString LeftAngle,
                                    QString RightAngle,
                                    QString MaterialName,
                                    QString Customer);
    // 达普打印动作 - 中文
    void printer_Active_DaPu_Zh(QString MaterialHeight,
                                QString MaterialLength,
                                QString LeftAngle,
                                QString RightAngle,
                                QString MaterialName,
                                QString Customer);
    // 达普打印动作 - 英文
    void printer_Active_DaPu_En(QString MaterialHeight,
                                QString MaterialLength,
                                QString LeftAngle,
                                QString RightAngle,
                                QString MaterialName,
                                QString Customer);

    int PrinterType() const;
    void setPrinterType(int newPrinterType);

    int CurrentLanguage() const;
    void setCurrentLanguage(int newCurrentLanguage);

    QString MaterialName() const;
    void setMaterialName(const QString &newMaterialName);

    QString CustomerName() const;
    void setCustomerName(const QString &newCustomerName);

signals:
    void PrinterTypeChanged();
    void CurrentLanguageChanged();

    void MaterialNameChanged();

    void CustomerNameChanged();

private:
    PrinterControl(QObject *parent = nullptr);
    ~PrinterControl();
    PrinterControl(const PrinterControl &) = delete;
    PrinterControl &operator=(const PrinterControl) = delete;

    QSerialPort *m_Printer = nullptr;

    int m_PrinterType;
    int m_CurrentLanguage;
    QString m_MaterialName;
    QString m_CustomerName;
};

#endif // PRINTERCONTROL_H
